<#-- 修改会员 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<base href="${baseURL}">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>修改会员 - ${title}</title>
	<meta name="keywords" content="${keywords}"/>
	<meta name="description" content="${description}"/>
	<link rel="shortcut icon" type="image/x-icon" href="${baseURL}${commonPath}images/favicon.ico" media="screen" />
	<link href="${commonPath}css/common.css" type="text/css" rel="stylesheet" >
	<script language="javascript" src="${commonPath}js/tool.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/ajax.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/json2.js" type="text/javascript"></script>
	<script src="${commonPath}js/cryptoJS/core.js" language="javascript" type="text/javascript"></script>
	<script src="${commonPath}js/cryptoJS/sha256.js" language="javascript" type="text/javascript"></script>
</head>

<script type="text/javascript" language="javascript"> 
	//确认提交
	function sureSubmit(objForm){
		if(allVerification() == false){
			alert("请填好资料再提交");
			return;
		}
		
		
		
		//密码需SHA256加密
		var password = document.getElementById("password").value;
		if(password != ""){
			document.getElementById("password").value = CryptoJS.SHA256(password);
			
			//旧密码
			var oldPassword = document.getElementById("oldPassword").value;
			if(oldPassword != ""){
				document.getElementById("oldPassword").value = CryptoJS.SHA256(oldPassword);
			}
		}
		document.getElementById("editUserForm").submit();
	}
	
	//ajax提交
	function ajaxSubmit(){
	
		if(allVerification() == false){
			alert("请填好资料再提交");
			return;
		}
	
		var parameter = getParameter();
		if(parameter.indexOf("&") == 0){
			parameter = parameter.substring(1,parameter.length);
		}
		post_request(function(value){
			if(value != ""){
				var returnValue = JSON.parse(value);//JSON转为对象
				for(var key in returnValue){
					if(key == "success"){	
						var success = returnValue[key];	
						if(success == "true"){
							alert("修改成功");
							//刷新当前在页面
							window.location.reload();
						}
					}else if(key == "error"){
						var errorValue = returnValue[key];
						for(var error in errorValue){
							if(error != ""){
								document.getElementById(error+"_error").innerHTML=errorValue[error];	
							}
						}
					}
				}
			}	
		},
			"user/control/editUser?&timestamp=" + new Date().getTime(), true,parameter);

	}

	
	//组装参数
	function getParameter(){
		var parameter = "";
		//令牌标记
		var token = document.getElementById("token").value;
		parameter += "&token="+token;

		//密码需SHA256加密
		var password = document.getElementById("password").value;
		if(password !=""){
			parameter += "&password="+ CryptoJS.SHA256(password);
			//旧密码
			var oldPassword = document.getElementById("oldPassword").value;
			if(oldPassword != ""){
				parameter += "&oldPassword="+ CryptoJS.SHA256(oldPassword);
			}
		}
		
		
		
		//自定义表单name集合
		var array = new Array();
		
		//读取表单所有的input标签
		var all_input = document.getElementsByTagName("input");
		for(var i=0;i<all_input.length; i++){
			var obj = all_input[i];
			if(obj.name.substring(0,11) =="userCustom_"){
				var isExist = false;//是否已存在数组中
				//如果存在，则不添加
				for(var j=0;j<array.length; j++){
					if(array[j] == all_input[i].name){
						isExist = true;
						break;
					}
				}
				if(isExist == false){
					array.push (all_input[i].name); 
				}		
			}
		}
		//读取表单所有的select标签
		var all_select = document.getElementsByTagName("select");
		for(var i=0;i<all_select.length; i++){
			var obj = all_select[i];
			if(obj.name.substring(0,11) =="userCustom_"){
				var isExist = false;//是否已存在数组中
				//如果存在，则不添加
				for(var j=0;j<array.length; j++){
					if(array[j] == all_select[i].name){
						isExist = true;
						break;
					}
				}
				if(isExist == false){
					array.push (all_select[i].name); 
				}		
			}
		}
		//读取表单所有的textarea标签
		var all_textarea = document.getElementsByTagName("textarea");
		for(var i=0;i<all_textarea.length; i++){
			var obj = all_textarea[i];
			if(obj.name.substring(0,11) =="userCustom_"){
				var isExist = false;//是否已存在数组中
				//如果存在，则不添加
				for(var j=0;j<array.length; j++){
					if(array[j] == all_textarea[i].name){
						isExist = true;
						break;
					}
				}
				if(isExist == false){
					array.push (all_textarea[i].name); 
				}		
			}
		}

		for(var i=0;i<array.length; i++){
			//读取表单参数
			var obj = document.getElementsByName(array[i]);
			if(obj[0].type == "text"){//输入框
			
				parameter += "&"+obj[0].name+"="+encodeURIComponent(obj[0].value);
			}
			if(obj[0].type == "radio"){//单选
				for(var j=0;j<obj.length;j++){ 
					if(obj[j].checked){
						parameter += "&"+obj[0].name+"="+obj[j].value;
						break; 
					}
				}
			}
			if(obj[0].type == "checkbox"){//多选
				for(var j=0;j<obj.length;j++){ 
					if(obj[j].checked){
						parameter += "&"+obj[0].name+"="+obj[j].value;
					}
				}
			}
			if(obj[0].type.substring(0,6) == "select"){//下拉列表
				for(var j=0;j<obj[0].length;j++){ 
					if(obj[0][j].selected){
						parameter += "&"+obj[0].name+"="+obj[0][j].value;
					}
				}
			}
			if(obj[0].type == "textarea"){//表单域
				parameter += "&"+obj[0].name+"="+encodeURIComponent(obj[0].value);
			
			}
		}
		

	
		//删除第一个&号,防止因为多了&号而出现警告: Parameters: Invalid chunk ignored.信息
		if(parameter.indexOf("&") == 0){
			parameter = parameter.substring(1,parameter.length);
		}
		return parameter;
	}
	
	
	
	
	//验证参数
	function verification(field){
		if(field == "password"){//密码
			var parameter = document.getElementById(field).value;
			if(parameter != ""){
				var parameter_trim = trim(parameter);
				if(parameter_trim != ""){
					if(getStringLeng(parameter_trim) < 6){
						document.getElementById(field+"_error").innerHTML = "密码长度不能小于6位";
						return false;
					}
					if(getStringLeng(parameter_trim) > 20){
						document.getElementById(field+"_error").innerHTML = "密码长度不能大于20位";
						return false;
					}
				}else{
					document.getElementById(field+"_error").innerHTML = "密码不能为空";
					return false;
				}
				//旧密码
				var oldPassword = document.getElementById("oldPassword").value;
				if(oldPassword == ""){
					document.getElementById("oldPassword_error").innerHTML = "旧密码不能为空";
				}
			}
		}
		if(field == "confirmPassword"){//确认密码
			var password = document.getElementById("password").value;
			
			var parameter = document.getElementById(field).value;
			if(password != parameter){
				document.getElementById(field+"_error").innerHTML = "两次密码不相等";
				return false;
			}
		}
	
		document.getElementById(field+"_error").innerHTML = "";
		return true;
	}
	
	//验证全部参数
	function allVerification(){
		var isVerification = true;
		if(verification("password") == false){
			isVerification = false;
		}
		if(verification("confirmPassword") == false){
			isVerification = false;
		}
		return isVerification;
	}

	//禁止浏览器后退
	window.history.forward(1);
	
</script>

<BODY>
<#-- 引入页头 -->
<@include action="${newPublic_2}"/>
<div class="fixedBottom wrap clearfix">
	<#-- 引入服务导航 -->
	<@include action="${newPublic_4}"/>
	
	<form id="editUserForm" method="post" autocomplete="off" action="user/control/editUser">
	<!-- 令牌标记 -->
	<input type="hidden" id="token" name="token" value="${token}">
	<div class="wrap">
		<div class="blankTableModule">
			<table class="blankTable" border="0" cellSpacing="2" cellPadding="0" width="100%">
				<tbody>
					<tr>
			    		<td width="120px" align="right">用户名： </td>
			    		<td align="left">${user.userName}</td>
					</tr>
					<tr>
						<td width="120px" align="right">旧密码： </td>
						<td align="left">
							<input type="password" id="oldPassword" name="oldPassword" class="formText" autocomplete="off" size="25" maxlength="20" onBlur="verification(this.id)"/>
							<span id="oldPassword_error" class="error">${(error['oldPassword'])!}</span>
							<span class="help">不修改密码请留空</span> 
						</td>
					</tr>
					<tr>
						<td width="120px" align="right">密码： </td>
						<td>
							<input type="password" id="password" name="password" class="formText" autocomplete="off" size="25" maxlength="20" onBlur="verification(this.id)"/>
							<span id="password_error" class="error">${(error['password'])!}</span>
							<span class="help">不修改请留空</span> 
						</td>
						
					</tr>
					<tr>
						<td width="120px" align="right">确认密码:</td>
						<td align="left">
							<input type="password" id="confirmPassword" class="formText" autocomplete="off" size="25" maxlength="20" onBlur="verification(this.id)"/>
							<span id="confirmPassword_error" class="error"></span>
							<span class="help">不修改请留空</span>
						</td>
					<tr>
					<!-- 用户自定义注册功能项 -->
					<#list userCustomList as userCustom>
					<tr>
						<td width="120px" align="right"><#if userCustom.required == true><span class="required">*</span></#if>${userCustom.name}:</td>
						<td align="left">
							<#if userCustom.chooseType ==1>
								<input type="text" class="formText" name="userCustom_${userCustom.id}" value="<#list userCustom.userInputValueList as userInputValue>${userInputValue.content}</#list>" size="${userCustom.size}" maxlength="${userCustom.maxlength}">
							</#if>
							<#if userCustom.chooseType ==2>
								<#if userCustom.itemValue?has_content>
									<#list userCustom.itemValue?keys as itemValue>
									<#-- 选中项 -->
									<#assign _checked = "">
									<#list userCustom.userInputValueList as userInputValue>
										<#if userInputValue.options == itemValue>
											<#assign _checked=" checked='checked'">
										</#if>
									</#list>
									
									<#-- 默认选第一项 -->
									<#if itemValue_index == 0  && userCustom.userInputValueList?exists && userCustom.userInputValueList?size == 0> 
									<#assign _checked = " checked='checked'">
									</#if>
									<input type="radio" name="userCustom_${userCustom.id}" value="${itemValue}" ${_checked} >${userCustom.itemValue[itemValue]}
									</#list>
								</#if>
							</#if>
							<#if userCustom.chooseType ==3>
								<#if userCustom.itemValue?has_content>
									<#list userCustom.itemValue?keys as itemValue>
										<#-- 选中项 -->
										<#assign _checked = "">
										<#list userCustom.userInputValueList as userInputValue>
											<#if userInputValue.options == itemValue>
												<#assign _checked=" checked='checked'">
											</#if>
										</#list>
										<input type="checkbox" name="userCustom_${userCustom.id}" value="${itemValue}" ${_checked}>${userCustom.itemValue[itemValue]}
									</#list>
								</#if>
							</#if>
							<#if userCustom.chooseType ==4>
								<select name="userCustom_${userCustom.id}" <#if userCustom.multiple == true> multiple='multiple'</#if> <#if userCustom.selete_size != null> size='${userCustom.selete_size}'</#if>>
									<#if userCustom.itemValue?has_content>
									<#list userCustom.itemValue?keys as itemValue>
										<#assign _selected = "">
										<#list userCustom.userInputValueList as userInputValue>
											<#if userInputValue.options == itemValue>
												<#assign _selected=" selected='selected'">
											</#if>
										</#list>			
										<option value="${itemValue}" ${_selected}>${userCustom.itemValue[itemValue]}</option>		
									</#list>
									</#if>	
								</select>
							</#if>
							<#if userCustom.chooseType ==5>
								<textarea name="userCustom_${userCustom.id}" rows="${userCustom.rows}" cols="${userCustom.cols}"><#list userCustom.userInputValueList as userInputValue>${userInputValue.content}</#list></textarea>
							</#if>
							<span class="help">${userCustom.tip}</span>
							<#assign userCustom_id = "userCustom_"+userCustom.id>
							<span id="userCustom_${userCustom.id}_error" class="error">${error[userCustom_id]}</span>
						</td>
					</tr>
					</#list>
					<tr>
						<td></td>
						<td>
							<span id="user_error" class="error">${error['user']}</span>  
							<span class="submitButton"><INPUT type="button" value="提交" onClick="javascript:sureSubmit();"></span>
							<!-- 
							<span class="submitButton"><INPUT type="button" value="ajax提交" onClick="javascript:ajaxSubmit();"></span>
							 -->
							<span id="token_error" class="error">${error['token']}</span>  
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
	</form>
	<div style="clear:both;"></div>
	<div class="push"><!-- 把div#footer推下去 --></div>
</div>
<#--引入页脚-->
<@include action="${newPublic_3}"/>
</BODY>

</HTML>
